// pages/stacks/stacks.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gender: 'male',
    type: '',
    major: '',
    minor: '',
    start: 0,
    limit: 20,
    update: '',
    types: [{
      type: 'hot',
      name: '热门'
    }, {
      type: 'new',
      name: '新书'
    }, {
      type: 'reputation',
      name: '好评'
    }, {
      type: 'over',
      name: '完结'
    }, {
      type: 'monthly',
      name: '包月'
    }],
    curIndex: 0,
    curIndex1: 0,
    curIndex2: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '书库'
    })
    var that = this
    wx.request({
      url: 'https://api.zhuishushenqi.com/cats/lv2', //仅为示例，并非真实的接口地址
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {

        console.log(res);

        console.log('db', res.data.male[0].mins);
        console.log('db1', res.data.male[0]);

        that.setData({
          category: res.data.male,
          mins: res.data.male[0].mins,

          update: 0,


          major: res.data.male[0]['major'],
          booktype: 'hot',
          bookminor: res.data.male[0].mins[0]
        }),
          that.getData()

      }
    })
  },

  setCategray: function (e) {
    var that = this;
    let index = parseInt(e.target.dataset.index);
    this.setData({
      curIndex: index,
      curIndex1: 0,
      bookminor: that.data.category[index].mins[0]
    })

    var major = e.target.dataset.name;
    that.data.major = major;
    that.data.update = index;

    that.getData()
  },


  //事件处理函数
  setType: function (e) {
    var that = this;
    let index = parseInt(e.target.dataset.index);
    var type = e.target.dataset.name;
    this.setData({
      curIndex2: index,
      booktype: type,
    })
    that.getData()
  },

  setMins: function (e) {
    var that = this;
    let index = parseInt(e.target.dataset.index);
    var bookminor = e.target.dataset.name;
    this.setData({
      curIndex1: index,
      bookminor: bookminor,
    })


    // that.data.major = major;
    // that.data.update = index


    that.getData()
  },


  getData: function (major) {
    var that = this;

    console.log('#2', that.data.major)


    console.log("QQQQ", that.data.major + '|' + that.data.booktype + '|' + that.data.bookminor);

    wx.request({
      url: 'https://api.zhuishushenqi.com/book/by-categories', //仅为示例，并非真实的接口地址
      method: 'GET',





      data: {
        gender: 'male',
        type: that.data.booktype,
        major: that.data.major,
        minor: that.data.bookminor,
        start: 0,
        limit: 20
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          books: res.data.books,
          mins: that.data.category[that.data.update].mins,

        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var self = this;
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})